package com.leyou.goods.listener;

import com.leyou.goods.service.GoodsHtmlService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @author: Mr_Sun
 * @Date: 2018/9/21
 * @Time: 16:03
 */
@Component
public class GoodsListener {
    @Autowired
    private GoodsHtmlService goodsHtmlService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "leyou.goods.create.queue",durable = "true"),
            exchange = @Exchange(value = "LEYOU.ITEM.EXCHANGE",ignoreDeclarationExceptions = "true",type = ExchangeTypes.TOPIC),
            key = {"item.update","item.insert"}
    ))
    public void listenCreate(Long id) {
        if (id == null ||id.longValue() <=0) {
            return;
        }
        this.goodsHtmlService.creatHtml(id);

    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "leyou.goods.delete.queue",durable = "true"),
            exchange = @Exchange(value = "LEYOU.ITEM.EXCHANGE",ignoreDeclarationExceptions = "true",type = ExchangeTypes.TOPIC),
            key = {"item.delete"}
    ))
    public void listenDelete(Long id) {
        if (id == null ||id.longValue() <=0) {
            return;
        }
        this.goodsHtmlService.deleteHtml(id);

    }
}
